package jdbc;

import java.sql.*;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try {
            Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement();
            String sql = "SELECT COUNT(*) FROM student t,class c WHERE t.class_id = c.id AND c.name = '1年级1班'";
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next()){
                int count = resultSet.getInt("COUNT(*)");
                System.out.println("1年级1班有"+count+"人");
            }
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
